<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
if(!empty($_POST['SurveyTitle'])){
	$SurveyOptions = $SurveyCount = NULL;
	for($i=1; $i<=$_POST['Item']; $i++){
		$n = str_replace('|','',$_POST['SurveyOptions'.$i]);
		$o = str_replace('|','',$_POST['SurveyCount'.$i]);
		if(!is_numeric($o)) $o = 0;
		$SurveyOptions .= $i==1 ? $n : '|'.$n;
		$SurveyCount .= $i==1 ? $o : '|'.$o;
	}
	$SQL = "INSERT INTO `{$dbprefix}survey` (`SurveyLang`,`SurveyTitle`,`SurveyStart`,`SurveyEnd`,`SurveyMany`,`SurveyOptions`,`SurveyCount`,`SurveySort`,`SurveyTime`) ";
	$SQL .="VALUES ('{$Lang}','{$_POST['SurveyTitle']}','{$_POST['SurveyStart']}','{$_POST['SurveyEnd']}','{$_POST['SurveyMany']}','{$SurveyOptions}','{$SurveyCount}','0',NOW());";
	if($db->ExecuteSQL($SQL,0)){
		AdminLog(2,$Lang,'添加调查，结果：操作成功！'); 
		MsgBox (1,'调查添加成功！','SurveyManage.php?Lang=' . $Lang);
	} else {
		AdminLog(2,$Lang,'添加调查，结果：操作失败！'); 
		MsgBox (1,'操作失败，请检查您提交的数据是否正确！','-1');
	}	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script language="javascript"> 
var i = 1;
var idHtml,x;
function AddItem(){ 
	i++;
	idHtml = '';
	if(i>20){
		i = 20;
		alert("最大只允许20个选项！");
		return;
	}
	var obj = document.getElementById("project");
	obj.innerHTML += '<ol style="line-height:30px;"><input type="text" name="SurveyOptions'+i+'" id="SurveyOptions'+i+'" class="input2" />&nbsp;<input type="text" name="SurveyCount'+i+'" id="SurveyCount'+i+'" value="0" style="width:40px; height:15px;" /></ol>'
}
function ResetItem(){ 
	i--;
	idHtml = '';
	if(i<1){
		i = 1;
		return;
	}
	for(x=1; x<i; x++){
		idHtml += '<ol style="line-height:30px;"><input type="text" name="SurveyOptions'+(x+1)+'" value="" class="input2" />&nbsp;<input type="text" name="SurveyCount'+(x+1)+'" value="0" style="width:40px; height:15px;" /></ol>'
	}
	document.getElementById("project").innerHTML = idHtml;
}
function checkSubmit(){
	$("#Item").val(i);
	$("ol input").appendTo("form"); //兼容GG、FF浏览器不提交动态表单元素
	if(document.survey.SurveyTitle.value==""){
		alert("调查标题不能为空！");
		document.survey.SurveyTitle.focus();
		return false;
	}
	return true;
}
</script> 
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
		<td><?php TopLang();?></td>
		<td align="right">
			<input type="button" value="调查管理" onClick="javascript:location.href='SurveyManage.php?Lang=<?php echo $Lang?>'">
		</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form name="survey" method="post" action="" onSubmit="return checkSubmit();">
  <tr>
    <td colspan="3" align="center" class="Main_Title">添加调查<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="right">调查标题：</td>
    <td><input type="text" value="" class="input2" name="SurveyTitle" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr class="odd">
    <td height="20" align="right">开始时间：</td>
    <td><input type="text" value="<?php echo date("Y-m-d H:i:s");?>" class="input2" name="SurveyStart" /></td>
    <td>格式：<?php echo date("Y-m-d H:i:s");?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="right">结束时间：</td>
    <td><input type="text" value="<?php echo date("Y-m-d H:i:s",time()+2592000);?>" class="input2" name="SurveyEnd" /></td>
    <td>格式：<?php echo date("Y-m-d H:i:s");?></td>
  </tr>
  <tr class="odd">
    <td height="20" align="right">单选复选：</td>
    <td>
		<input type="radio" name="SurveyMany" value="0" />单选
    	<input type="radio" name="SurveyMany" value="1" checked="checked" />多选
	</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="odd">
    <td height="20" align="right" valign="top" style="padding:5px 4px 0 0;">调查选项：</td>
    <td>
		<table cellpadding="0" cellspacing="0"><tr>
		<td>
			<div>
				<input type="text" name="SurveyOptions1" value="" class="input2" />
				<input type="text" name="SurveyCount1" value="0" style="width:40px; height:15px;" />
			</div>
			<div id="project"></div>
		</td>
		<td width="30" align="center" valign="top" style="padding:3px 0 0 0;"><a href="javascript:AddItem();"><img src="images/add.gif" width="15" height="15" border="0" /></a></td>
		<td valign="top" style="padding:3px 0 0 0;"><a href="javascript:ResetItem();"><img src="images/cut.gif" width="15" height="15" border="0" /></a></td>
		</tr></table>
	</td>
    <td>调查选项及初始投票数据</td>
  </tr>
  <!--tr class="odd">
  	<td height="20" align="right">排序字段：</td>
  	<td><input type="text" value="0" class="input2" name="SurveySort" /></td>
  	<td>降序，值越大越靠前。</td>
  	</tr-->
  <tr class="odd">
    <td height="20" align="right">&nbsp;</td>
    <td>
		<input type="hidden" name="Item" id="Item" value="1" />
		<input type="submit" name="button" id="button" value="提 交" />
	</td>
    <td>&nbsp;</td>
  </tr>
</form>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">&nbsp;</td>
	</tr>
</table>  
</body>
</html>
